import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import refresh from "@dfeidao/atom-web/url/refresh"
import upload from '@dfeidao/atom-web/file/upload';
import { productid } from '../../atom/config';
export default async function a003(fd: IFeidaoAiBrowserComponent) {
	// todo
	const event_theme = fd.data.node.querySelector<HTMLInputElement>('[data-id="event_theme"]').value;
	if (!event_theme) {
		alert('请输入事件主题');
		return;
	}


	const principal_part1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="principal_part"]');
	const principal_part = principal_part1.value;
	if (principal_part === '请选择') {
		alert('请选择负责部门');
		return;
	}


	const management_office1 = fd.data.node.querySelector<HTMLSelectElement>('[data-id="management_office"]');
	const management_office = management_office1.value;
	if (management_office === '请选择') {
		alert('请选择管理处');
		return;
	}
	console.log('管理处', management_office);
	const event_time = fd.data.node.querySelector<HTMLInputElement>('[data-id="event_time"]').value;
	const now_date = new Date(event_time).getTime();
	console.log(now_date);

	if (!event_time) {
		alert('请输入事件时间');
		return;
	}


	const event_location = fd.data.node.querySelector<HTMLInputElement>('[data-id="event_location"]').value;
	if (!event_location) {
		alert('请输入事发地点');
		return;
	}


	const event_record = fd.data.node.querySelector<HTMLInputElement>('[data-id="event_record"]').value;
	if (!event_record) {
		alert('请输入事件记录');
		return;
	}


	const process_result = fd.data.node.querySelector<HTMLInputElement>('[data-id="process_result"]').value;
	if (!process_result) {
		alert('请输入处理结果');
		return;
	}


	const cause_analysis = fd.data.node.querySelector<HTMLInputElement>('[data-id="cause_analysis"]').value;
	if (!cause_analysis) {
		alert('请输入原因分析');
		return;
	}


	const precaution = fd.data.node.querySelector<HTMLInputElement>('[data-id="precaution"]').value;
	if (!precaution) {
		alert('请输入预防措施');
		return;
	}


	const principal_opinion = fd.data.node.querySelector<HTMLInputElement>('[data-id="principal_opinion"]').value;
	if (!principal_opinion) {
		alert('请输入负责人意见');
		return;
	}


	const memo = fd.data.node.querySelector<HTMLInputElement>('[data-id="memo"]').value;
	if (!memo) {
		alert('请输入备注');
		return;
	}



	const resume_attachment = fd.data.node.querySelector<HTMLInputElement>('[data-id="resume_attachment"]');
	const res = await upload(productid, resume_attachment);
	const resume_attachment_v = res.filename;
	if (!resume_attachment_v) {
		alert('请上传附件');
		return;
	}






	const event_no = get(fd, 'no')

	const r = await nodejs<{ code: 0 | 1; result: string; }>('LiQiuLiang/zj-000004/s001', {
		data: {
			event_location,
			event_record,
			process_result,
			cause_analysis,
			precaution,
			principal_opinion,
			memo,
			event_theme,
			event_no,
			resume_attachment: resume_attachment_v,
			principal_part,
			management_office,
			event_time: now_date,

		},
	});
	console.log('999', r);

	if (r.code === 1) {
		alert('保存成功');
		refresh();
	} else {
		alert('保存失败');
	}
}
